<%@ taglib prefix="c"   uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@page import="org.apache.commons.beanutils.locale.*" %>
<c:import url="/app/soci/disponibilita_map.jsp" /> 
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet"  href="<%=request.getContextPath()%>/css/display.css?v=0.001" type="text/css" media="screen" />
<script src="<%=request.getContextPath()%>/js/jquery.js?v=0.001"></script>
<script src="<%=request.getContextPath()%>/js/autocomplete.js"></script>
<script src="<%=request.getContextPath()%>/js/form.js"></script> 
<script type="text/javascript" src='<%=request.getContextPath()%>/js/input01.js'></script>
<% facades.SessionFacade sfacade = facades.SessionFacade.getInstance(request); %>
<title>Gestione Auser - Accompagnamenti</title>

</head>
<body> 
	  
	 <h1>Lavori in corso</h1> 
	 <form method="post" action="save.jsp" name="formData" id=""formData"">
		 <c:if test="${empty param.id}" >
		 	<h1>Aggiunta di un Accompagnamento</h1>   
		 	<input type="hidden" name="EditMode" value="ADD" />
		 </c:if>
		 
		 <c:if test="${!empty param.id}" >
		 	<h1>Dati Accompagnamento</h1> 
		 	<input type="hidden" name="EditMode" value="EDIT" />
		 </c:if>
		 
		 
		<fieldset>
			<legend>Dati principali</legend>  
	
	 		<label for='dataAccompagnamento'>Data</label>
	 		<input name="dataAccompagnamento"  id="dataAccompagnamento" value="<fmt:formatDate pattern="dd/MM/yyyy" value='${editAccompa.dataAccompagnamento}'/>" class="Date">		
	 		<label class='validError'>${eDataAccompagnamento}</label><br/>
	 		
	 		<label for='motivo'>Motivo</label>
	 		
	 			<select id="idMotivo" name="idMotivo">
	 				<option value=""></option>
	 				<c:forEach items="<%=sfacade.querySql("From auser.MotiviAccompagnamento m order by descrizione") %>" var="obj">
	 					<c:set var="objId" value="<%=sfacade.getID("obj",pageContext) %>" /> 
	 					<option value="${objId}" ${obj==editAccompa.motivo?"selected":"" } >${obj.descrizione}</option>
					</c:forEach>
	 			</select> 
	 			<label class='validError'>${eIdMotivo}</label><br/>
	 		 
	 		<label for='motivo'>Accompagna</label>
	 			<select id="idAccompagna" name="idAccompagna" >
	 				<option value=""></option>
	 				<c:forEach items="<%=sfacade.querySql("From auser.SoggettoAccompagnato s order by cognome,nome ") %>" var="obj">
	 					<c:set var="objId" value="<%=sfacade.getID("obj",pageContext) %>" /> 
	 					<option value="${objId}" ${obj==editAccompa.disabile?"selected":"" }>${obj.cognome} ${obj.nome}</option>
					</c:forEach>
	 			</select> 
	 			<label class='validError'>${eIdAccompagna}</label><br/>
	 		 	 
	 	</fieldset>	
	 	
	 	<fieldset>
			<legend>Accompagnatore</legend>	
	 		<c:set var="listaDisponibilita">
	 			<option value="*">-- Tutte le disponibilità --</option>
	 			<c:forEach items="${disponibilita}" var="obj" >
 					<option value="${obj.key}" >${obj.value}</option>
				</c:forEach>
	 		</c:set>
	 		
	 		<c:set var="accompagnatore" value="${editAccompa.accompagnatore}" /> 
 			<c:set var="objId" value="<%=sfacade.getID("accompagnatore",pageContext) %>" /> 
	 		<input type="hidden" name="idAccompagnatore" id="idAccompagnatore"  value="${objId}" />
	 		<label for='disponibilita'>Accompagnatore</label>
	 			<select style="margin-right:0" id="disponibilita" name="disponibilita">  
	 				${listaDisponibilita} 
	 			</select>
	 			
	 			 
	 			<input class="autocomplete" style='margin-left:0;background-color:lightblue' type="text" name="nomeAccompagnatore" id="nomeAccompagnatore" size="33" value="${editAccompa.accompagnatore.cognome} ${editAccompa.accompagnatore.nome}" /> 
	 			<a href="#" onclick="acnomeAccompagnatore.showList();return false">[Elenco]</a> <br>
	 		 
	 		<hr size="1">
	 		<label for='modello'>Mezzo Proprio</label> 
	 			<select name="idMezzoProprioAccompagnatore" id="idMezzoProprioAccompagnatore">
	 				<option value=""></option>
	 				<c:forEach items="<%=sfacade.querySql("MezziAccompagnato","o.tipo='Proprio' or o.tipo='proprio'","o.descrizione",true) %>" var="obj">
	 					<c:set var="objId" value="<%=sfacade.getID("obj",pageContext) %>" />
	 					<option value="${objId}" ${obj==editAccompa.mezzoProprioAccompagnatore?"selected":""} >${obj.descrizione}  </option>
					</c:forEach>
	 			</select> 
	 			 
	 			  
	 		 
	 		<label  style="margin-left:0" for='rimborsoKm'>Km fatti</label>
	 		<input class="Float" type="text" name="kmMezzoProprioAccompagnatore" id="kmMezzoProprioAccompagnatore"  size="5" value="<fmt:formatNumber pattern="0.00" value="${editAccompa.kmMezzoProprioAccompagnatore}"  />"  /> 
	 		<label class='validError'>${eKmMezzoProprioAccompagnatore}</label><br/>	
			 
	 			
	 	</fieldset>	
	 	<fieldset>		 
 		
			<legend>Autista</legend>	
			
			<c:set var="autista" value="${editAccompa.autista}" /> 
 			<c:set var="objId" value="<%=sfacade.getID("autista",pageContext) %>" /> 
	 		<input type="hidden" name="idAutista" id="idAutista" value="${objId}" />
	 		
	 		<label for='disponibilitaAutista'>Autista</label>
 			<select style="margin-right:0" id="disponibilitaAutista" name="disponibilitaAutista"> 
 				${listaDisponibilita}
 			</select>
 			 
 			<input class="autocomplete" style='margin-left:0;background-color:lightblue' type="text" name="nomeAutista" id="nomeAutista" size="33" value="${editAccompa.autista.cognome} ${editAccompa.autista.nome}" /> 
 			<a href="#" onclick="acnomeAutista.showList();return false">[Elenco]</a> <br>
 			<hr size="1">
 			<label for='modello'>Mezzo Proprio</label>
	 			<select name="idMezzoProprioAutista" id="idMezzoProprioAutista">
	 				<option value=""></option>
	 				<c:forEach items="<%=sfacade.querySql("MezziAccompagnato","o.tipo='Proprio' or o.tipo='proprio'","o.descrizione",true) %>" var="obj">
	 					<c:set var="objId" value="<%=sfacade.getID("obj",pageContext) %>" />
	 					<option value="${objId}" ${obj==editAccompa.mezzoProprioAutista?"selected":""} >${obj.descrizione}  </option>
					</c:forEach>
	 			</select> 
	 		
	 		 
	 		<label  style="margin-left:0" for='rimborsoKm'>Km fatti</label>
	 		<input class="Float" type="text" name="kmMezzoProprioAutista" id="kmMezzoProprioAutista"  size="5" value="<fmt:formatNumber pattern="0.00" value="${editAccompa.kmMezzoProprioAutista}"  />"  /> 
	 		<label class='validError'>${eKmMezzoProprioAutista}</label><br/>		
	 		
	 		<hr size="1">
	 		
	 		<label for='modello'>Mezzo Auser</label>
	 			<select name="idMezzoAuserAutista" id="idMezzoAuserAutista">
	 				<option value=""></option>
	 				<c:forEach items="<%=sfacade.querySql("MezziAccompagnato","o.tipo='Auser' or o.tipo='auser'","o.descrizione",true) %>" var="obj">
	 					<c:set var="objId" value="<%=sfacade.getID("obj",pageContext) %>" />
	 					<option value="${objId}" ${obj==editAccompa.mezzoAuserAutista?"selected":""} >${obj.descrizione}  </option>
					</c:forEach>
	 			</select> 
	 		 
	 		<label  style="margin-left:0" for='rimborsoKm'>Km fatti</label>
	 		<input class="Float" type="text" name="kmMezzoAuserAutista" id="kmMezzoAuserAutista"  size="5" value="<fmt:formatNumber pattern="0.00" value="${editAccompa.kmMezzoAuserAutista}"  />"  /> 
	 		
			<label class='validError'>${eKmMezzoAuserAutista}</label><br/>	
	 		 
 		</fieldset> 
 		<fieldset> 
 			<legend>Spese</legend>
	 		<label>Autostrada   </label> <input type="text" name="speseAutostrada" id="speseAutostrada"  value="<fmt:formatNumber pattern="0.00" value="${editAccompa.speseAutostrada}"  />" class="Float" maxlength="10"  />
			<label>Parcheggi  </label> <input type="text" name="speseParcheggi" id="speseParcheggi"  value="<fmt:formatNumber pattern="0.00" value="${editAccompa.speseParcheggi}"  />" class="Float" maxlength="10"  />
	 		<br>
			<label>Treno  </label> <input type="text" name="speseTreno" id="speseTreno"  value="<fmt:formatNumber pattern="0.00" value="${editAccompa.speseTreno}"  />" class="Float" maxlength="10"  />
			<label>Cibo  </label> <input type="text" name="speseCibo" id="speseCibo"  value="<fmt:formatNumber pattern="0.00" value="${editAccompa.speseCibo}"  />" class="Float" maxlength="10"  />
			<br>
	 
	
			<label>Altre Spese </label> <input type="text" name="speseAltre" id="speseAltre" class="Float" maxlength="10"  value="<fmt:formatNumber pattern="0.00" value="${editAccompa.speseAltre}"  />" />
	
	 			 
	 		  
			<input style='float:right' class='button' type='button' value='Esci senza salvare' id='btnClose' onclick='document.location="<%=request.getContextPath()%>/app/start/index.jsp"'> 
	 		<input style='float:right' class='button' type='submit' value='Salva' id='btnSave' />		
		</fieldset>	
 
 
 <script>
	function selectItemAc(li) {
		 
		if (li.extra) {
			$("#idAccompagnatore").val(li.extra[1]); 
		}
		 	
	}
	
	function selectItemAu(li) {
		if (li.extra) {
			$("#idAutista").val(li.extra[1]); 
		}
		 	
	}
	
	function formatItem(row) { 
		return "<b>" + row[0]+"</b><br>" + row[1]  ;
	}
	
	 
	
	var acnomeAccompagnatore = null;
	var acnomeAutista = null;
	
	$(document).ready(function() {
	
		
		 
		$("#disponibilita").change(function(){
			try{ 
				acnomeAccompagnatore.hideList();
				acnomeAccompagnatore.flushCache(); 
				acnomeAccompagnatore.setExtraParams( { disponibilita:this.value  } )  ; 
			}catch(e){  alert(e.message); }
		}) ;
		
		
		$("#disponibilitaAutista").change(function(){
			try{ 
				acnomeAutista.hideList();
				acnomeAutista.flushCache(); 
				acnomeAutista.setExtraParams( { disponibilita:this.value  } )  ; 
			}catch(e){  alert(e.message); }
		}) ;
			
		$("body").click(function(){
			$(".autocomplete").each(function(){
				this.autocompleter.hideList();
			});
		});	
		
		$("#nomeAccompagnatore")
			.focus(function(){ this.value = "" ;  $("#idAccompagnatore").val("");   })
			.autocomplete("<%=request.getContextPath()%>/app/soci/lookupperdisp.jsp", { minChars:1,  matchContains:0, cacheLength:30, onItemSelect:selectItemAc, formatItem:formatItem, selectOnly:1, extraParams:{ "disponibilita":$("#disponibilita").val()  }  });
		
		$("#nomeAutista")
			.focus(function(){ this.value = "" ;  $("#idAutista").val(""); })
			.autocomplete("<%=request.getContextPath()%>/app/soci/lookupperdisp.jsp", { minChars:1,  matchContains:0, cacheLength:30, onItemSelect:selectItemAu, formatItem:formatItem, selectOnly:1, extraParams:{ "disponibilita":$("#disponibilitaAutista").val()  }  });
		
		$("#idMezzoProprioAccompagnatore").change(function(){
			$("#kmMezzoProprioAccompagnatore").val("0,00");
		})
		
		$("#idMezzoProprioAutista").change(function(){
			$("#kmMezzoProprioAutista").val("0,00");
		})
		
		$("#idMezzoAuserAutista").change(function(){
			$("#kmMezzoAuserAutista").val("0,00");
		})
		
		acnomeAccompagnatore=$("#nomeAccompagnatore" )[0].autocompleter; 
		acnomeAutista=$("#nomeAutista" )[0].autocompleter; 
		
	});
</script>

	
</body>
</html>